﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace A14_Ex06_Noam_300476694_Shai_300380698
{
    public class GameSettings : Form
    {
        #region Data Members

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.CheckBox checkBox1_Computer;
        private System.Windows.Forms.TextBox textBox_Player1;
        private System.Windows.Forms.TextBox textBox_Player2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.NumericUpDown numericUpDown_Rows;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.NumericUpDown numericUpDown_Cols;
        private System.Windows.Forms.Button button_Start;

        #endregion

        public GameSettings()
        {
            InitializeComponent();
        }

        #region Properties

        public uint Cols 
        {
            get { return (uint)this.numericUpDown_Cols.Value; }
        }

        public uint Rows
        {
            get { return (uint)this.numericUpDown_Rows.Value; }
        }

        public ePlayerType PlayerType
        {
            get
            {
                return this.checkBox1_Computer.Checked == true ? ePlayerType.Human : ePlayerType.Computer;
            }
        }

        public string Player1
        {
            get { return textBox_Player1.Text; }
        }

        public string Player2
        {
            get { return textBox_Player2.Text; }
        }

        #endregion

        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.checkBox1_Computer = new System.Windows.Forms.CheckBox();
            this.textBox_Player1 = new System.Windows.Forms.TextBox();
            this.textBox_Player2 = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.numericUpDown_Rows = new System.Windows.Forms.NumericUpDown();
            this.label5 = new System.Windows.Forms.Label();
            this.numericUpDown_Cols = new System.Windows.Forms.NumericUpDown();
            this.button_Start = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_Rows)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_Cols)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(13, 13);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(44, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Players:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(37, 38);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(48, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "Player 1:";
            // 
            // checkBox1_Computer
            // 
            this.checkBox1_Computer.AutoSize = true;
            this.checkBox1_Computer.Location = new System.Drawing.Point(21, 61);
            this.checkBox1_Computer.Name = "checkBox1_Computer";
            this.checkBox1_Computer.Size = new System.Drawing.Size(67, 17);
            this.checkBox1_Computer.TabIndex = 3;
            this.checkBox1_Computer.Text = "Player 2:";
            this.checkBox1_Computer.UseVisualStyleBackColor = true;
            this.checkBox1_Computer.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
            // 
            // textBox_Player1
            // 
            this.textBox_Player1.Location = new System.Drawing.Point(105, 30);
            this.textBox_Player1.Name = "textBox_Player1";
            this.textBox_Player1.Size = new System.Drawing.Size(100, 20);
            this.textBox_Player1.TabIndex = 4;
            // 
            // textBox_Player2
            // 
            this.textBox_Player2.Enabled = false;
            this.textBox_Player2.Location = new System.Drawing.Point(105, 61);
            this.textBox_Player2.Name = "textBox_Player2";
            this.textBox_Player2.Size = new System.Drawing.Size(100, 20);
            this.textBox_Player2.TabIndex = 5;
            this.textBox_Player2.Text = "[Computer]";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(13, 103);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(61, 13);
            this.label3.TabIndex = 6;
            this.label3.Text = "Board Size:";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(37, 128);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(37, 13);
            this.label4.TabIndex = 7;
            this.label4.Text = "Rows:";
            // 
            // numericUpDown_Rows
            // 
            this.numericUpDown_Rows.Location = new System.Drawing.Point(80, 126);
            this.numericUpDown_Rows.Maximum = new decimal(new int[] {
            10,
            0,
            0,
            0});
            this.numericUpDown_Rows.Minimum = new decimal(new int[] {
            4,
            0,
            0,
            0});
            this.numericUpDown_Rows.Name = "numericUpDown_Rows";
            this.numericUpDown_Rows.Size = new System.Drawing.Size(37, 20);
            this.numericUpDown_Rows.TabIndex = 8;
            this.numericUpDown_Rows.Value = new decimal(new int[] {
            4,
            0,
            0,
            0});
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(132, 128);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(30, 13);
            this.label5.TabIndex = 9;
            this.label5.Text = "Cols:";
            // 
            // numericUpDown_Cols
            // 
            this.numericUpDown_Cols.Location = new System.Drawing.Point(168, 126);
            this.numericUpDown_Cols.Maximum = new decimal(new int[] {
            10,
            0,
            0,
            0});
            this.numericUpDown_Cols.Minimum = new decimal(new int[] {
            4,
            0,
            0,
            0});
            this.numericUpDown_Cols.Name = "numericUpDown_Cols";
            this.numericUpDown_Cols.Size = new System.Drawing.Size(37, 20);
            this.numericUpDown_Cols.TabIndex = 10;
            this.numericUpDown_Cols.Value = new decimal(new int[] {
            4,
            0,
            0,
            0});
            // 
            // button_Start
            // 
            this.button_Start.Location = new System.Drawing.Point(21, 165);
            this.button_Start.Name = "button_Start";
            this.button_Start.Size = new System.Drawing.Size(193, 20);
            this.button_Start.TabIndex = 11;
            this.button_Start.Text = "Start!";
            this.button_Start.UseVisualStyleBackColor = true;
            this.button_Start.Click += new System.EventHandler(this.button_Start_Click);
            // 
            // GameSettings
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(229, 201);
            this.Controls.Add(this.button_Start);
            this.Controls.Add(this.numericUpDown_Cols);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.numericUpDown_Rows);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.textBox_Player2);
            this.Controls.Add(this.textBox_Player1);
            this.Controls.Add(this.checkBox1_Computer);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "GameSettings";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "Game Settings";
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_Rows)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown_Cols)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }

            base.Dispose(disposing);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBox1_Computer.Checked)
            {
                this.textBox_Player2.Text = string.Empty;
                this.textBox_Player2.Enabled = true;
            }
            else
            {
                this.textBox_Player2.Text = "[Computer]";
                this.textBox_Player2.Enabled = false;
            }
        }

        private void button_Start_Click(object sender, EventArgs e)
        {
            if (checkMendatorySettingsAreSetAndAlertIfNot())
            {
                this.DialogResult = DialogResult.OK;
            }
        }

        private bool checkMendatorySettingsAreSetAndAlertIfNot()
        {
            bool result = false;

            if (this.textBox_Player1.Text == string.Empty)
            {
                showMessageBoxWithOK("Please fill Player1 text box");
                result = false;
            }
            else if (this.textBox_Player2.Text == string.Empty)
            {
                showMessageBoxWithOK("Please fill Player2 text box");
                result = false;
            }
            else if (this.numericUpDown_Cols.Value < 4 || this.numericUpDown_Cols.Value > 8)
            {
                showMessageBoxWithOK("Cols exceed allowed values");
                result = false;
            }
            else if (this.numericUpDown_Rows.Value < 4 || this.numericUpDown_Rows.Value > 8)
            {
                showMessageBoxWithOK("Rows exceed allowed values");
                result = false;
            }
            else
            {
                result = true;
            }

            return result;
        }

        private void showMessageBoxWithOK(string i_Message)
        {
            MessageBox.Show(i_Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
